import java.util.Arrays;

public class SelectSort {
    static int[] selectSort(int[] arr){

        for (int i = 0; i < arr.length-1; i++) {
            int minIndex=i;
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j]<arr[minIndex]){
                    minIndex=j;
                }
            }
            if (minIndex!=i){
                swap(arr,i,minIndex);
            }
        }
        return arr;
    }
    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    public static void main(String[] args) {
        System.out.println( Arrays.toString(selectSort(new int[]{9, 8, 5, 6, 7, 5, 6, 2, 4, 98, 5, 87, 2, 6, 2, 0, 5, 5, 9})));
    }
}
